/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import java.net.*;
import java.io.*;
/**
 *
 * @author Michael
 */
public class Client {

static final String ANMELDUNG = "ANMELDUNG";
static final String ENDE = "ENDE";
static int port = 1337;
static int length = 256; // Länge eines Pakets

public static void main( String args[]) {
    String servername = "localhost";
    String text = null;
    DatagramPacket packet;
    byte[] ba = ANMELDUNG.getBytes();

    // Namen des Servers von Kommandozeile übernehmen
    if( args.length > 0 ) servername = args[0];
    try {
        DatagramSocket socket = new DatagramSocket();
        InetAddress ia = InetAddress.getByName(servername);
        packet = new DatagramPacket( ba, ba.length, ia, port);
        // sende Anmeldung
        // socket.send( packet );

        // Lesen der empfangenen Pakete erfolgt in eigenem Thread
        LeseThread lt = new LeseThread( socket );

        // Eingaben von Tastatur an Server schicken
        BufferedReader br = new BufferedReader(new InputStreamReader( System.in ) );
        do {
            text = br.readLine();
            ba = text.getBytes();
            packet.setData( ba, 0, ba.length );
            socket.send( packet );
        } while( ! text.equals("ENDE") );
        // alles beenden
        System.exit(0);
    }
    catch( IOException e ) {
        System.err.println("Ausnahmefehler: " + e );
    }
}
}
